//
//  BaseResquest.m
//  LotteryClient
//
//  Created by SunYu on 14-2-6.
//  Copyright (c) 2014年 SunYu. All rights reserved.
//

#import "BaseResquest.h"

static NSString *defaultWebServiceUrl = nil;
@implementation BaseResquest
DEF_STATIC_PROPERTY_INT(baseType, BaseTypeRequest)

+ (void)setDefaultWebServiceUrl:(NSString *)webServiceUrl
{

	defaultWebServiceUrl = [webServiceUrl copy];
}

+ (NSString *)defaultWebServiceUrl
{
	return defaultWebServiceUrl;
}

+ (BaseResquest *)requestWithDefaultWebServiceURL
{
	NSURL *URL = [NSURL URLWithString:defaultWebServiceUrl];

 	return [self requestWithWebServiceURL:URL];
}


+ (BaseResquest *)requestWithWebServiceURL:(NSURL *)url
{
	if ([url isMemberOfClass:[NSString class]])
	{
		url = [NSURL URLWithString:(NSString *)url];
	}

	BaseResquest *baseRequest = [[BaseResquest alloc] init];

    baseRequest.request = [NSMutableURLRequest requestWithURL:url];
    if(baseRequest.request)
	{
		NSMutableDictionary *header = [NSMutableDictionary dictionary];
		[header setObject:kPlatform forKey:@"Client-Source"];
		[header setObject:kAppVersion forKey:@"Client-Version"];
		[header setObject:kChannelId forKey:@"Client-Channel"];
		[baseRequest.request setAllHTTPHeaderFields:header];
	}

	return baseRequest;
}

+ (BaseResquest *)requestWithWebServiceURLString:(NSString *)urlString
{
	return [[self class] requestWithWebServiceURL:[NSURL URLWithString:urlString]];
}

- (void)addRequestHeader:(NSString *)value andKey:(NSString *)key
{
	NSMutableDictionary *headers = [NSMutableDictionary dictionaryWithDictionary:self.request.allHTTPHeaderFields];
	[headers setObject:value forKey:key];
	[self.request setAllHTTPHeaderFields:headers];
}



@end
